package com.twu.biblioteca.security;

import com.twu.biblioteca.model.Customer;
import com.twu.biblioteca.domain.Library;
import com.twu.biblioteca.command.Command;

import java.util.List;

public class SecuritySupport {

    private Library library;

    private List<Class> securityRequiredCommands;

    public boolean authenticate(String userId, String password) {
        for (Customer customer : library.getCustomers()) {
            if (userId.equals(customer.getUserId()) && password.equals(customer.getPassword())) {
                library.setLoginInCustomer(customer);
                return true;
            }
        }
        return false;
    }

    public void setLibrary(Library library) {
        this.library = library;
    }

    public void setSecurityRequiredCommands(List<Class> securityRequiredCommands) {
        this.securityRequiredCommands = securityRequiredCommands;
    }

    public boolean authenticatedRequired(Class<? extends Command> commandClass) {
        return securityRequiredCommands.contains(commandClass);
    }
}
